package com.woniu.service.impl;

import com.woniu.dao.ClientMortgageInfoDao;
import com.woniu.dao.HouseManagerDao;
import com.woniu.entity.ClientMortgageInfo;
import com.woniu.entity.HouseManager;
import com.woniu.service.HouseManagerService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class HouseManagerServiceImpl implements HouseManagerService {
    @Resource
    @Qualifier("houseManagerDao")
    HouseManagerDao houseManagerDao;

    @Resource
    @Qualifier("clientMortgageInfoDao")
    ClientMortgageInfoDao clientMortgageInfoDao;
    @Override
    public List<HouseManager> findAll(HouseManager houseManager) {
        List<HouseManager> all = houseManagerDao.findAll(houseManager);
        for (HouseManager hm:all){

            Integer clientMortgageInfoId=hm.getClientMortgageInfoId();
            ClientMortgageInfo clientMortgageInfo=clientMortgageInfoDao.findHouseId(clientMortgageInfoId);
            if(Objects.nonNull(clientMortgageInfo)){
                Integer id=clientMortgageInfo.getId();
                hm.setId(id);
                String clientName=clientMortgageInfo.getClientName();
                hm.setClientName(clientName);
                String borrowStatus=clientMortgageInfo.getBorrowStatus();
                hm.setBorrowStatus(borrowStatus);
                String source=clientMortgageInfo.getSource();
                hm.setSource(source);
                String clientPhone=clientMortgageInfo.getClientPhone();
                hm.setClientPhone(clientPhone);
            }else {
                hm.setId(0);
                hm.setClientName("未知");
                hm.setBorrowStatus("未知");
                hm.setSource("未知");
                hm.setClientPhone("未知");
            }
            //System.out.println("当前"+hm.toString());
        }

        return all;
    }

    @Override
    public HouseManager findOne(String id) {
        HouseManager list = houseManagerDao.findOne(id);
        return list;
    }

    @Override
    public List<HouseManager> exportmortList() {
        return houseManagerDao.exportmortList();
    }
}
